package com.zxc.controller;

        import com.zxc.entity.User;
        import org.springframework.format.annotation.DateTimeFormat;
        import org.springframework.stereotype.Controller;
        import org.springframework.web.bind.annotation.PathVariable;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestParam;

        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        import javax.servlet.http.HttpSession;
        import java.util.Date;
        import java.util.Map;

/**
 * @author: zxc
 * @return:
 * @time:  2021/5/19 10:45
 * @description: @Controller控制器注解   @RequestMapping路径
 */
@Controller
@RequestMapping("/demo")
public class DemoController {


    @RequestMapping("/d1")
    public String demo1 () {
        System.out.println("测试");

        //spring-mvc.xml已经做了处理省略前后
        //返回 跳转.jsp文件
//        return "index";
        return "demo";
    }

    /**
      * @author: zxc
      * @return:
      * @time:  2021/5/19 15:42
      * @description: 获取参数数据 在网页输入和key值对应
      */
    @RequestMapping("/d2")
    public String demo2(String name, int age, @DateTimeFormat(pattern = "yyyy-MM-dd") Date bornDate) {
        System.out.println("name:"+name);
        System.out.println("age:"+age);
        System.out.println("bornDate:"+bornDate);
        return "demo";
    }

    @RequestMapping("/d3")
    public String demo3(User u){
        System.out.println(u);
        return "demo";
    }

    @RequestMapping("/d4")
    public String demo4(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        System.out.println(request.getParameter("name"));
        return "demo";
    }

    @RequestMapping("/d5")
    public String demo4(@RequestParam Map<String,Object> maps){
        System.out.println(maps);
        return "demo";
    }

    @RequestMapping("/d6")
    public String demo4(@RequestParam(name = "name",required = false) String ename){
        System.out.println(ename);
        return "demo";
    }

    @RequestMapping("/d7/{ename}/64684668{id}41684964")
    public String demo5(@PathVariable("ename") String name, @PathVariable int id){
        System.out.println(name);
        System.out.println(id);
        return "demo";
    }
}
